Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
Match "After" if it doesn't have an an -ing word after it

I want to match After if there isn't an -ing word after it (and before a comma). So there shouldn't be an -ing word between After and the comma.

Desired match (bold):

After sitting down, he began to talk.

After finally sitting down, he began to talk.

After he sat down, he began to talk.

I thought this regex would do it:

\bAfter\b.*(?!\w+ing)+,

But it's also matching After if there isn't an -ing word after it:

After sitting down, he began to talk.

After finally sitting down, he began to talk.

After he sat down, he began to talk.

https://regexr.com/683bv

Why is this and how to fix it?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try this regex

Matches only sentence from After and a comma, where there's no word with -ing after the wo

Just a lazy quantifier to the .+ (which instead of \w+in your regex) does the trick

\bAfter (?!.+?ing).*?,

(And also a lazy quantifier after the second .*, just in case if there's 2 commas in the same sentence)

Output:

img

Regex101 Demo

Tell me if its not working for you...

about 4 years ago · Juan Pablo Isaza Denunciar

0

The pattern you tried:

  • Using .* will first match the whole line, then it will backtrack to match the first encountered comma, so it will also match all comma's in between.
  • It can match the first encountered comma because this part (?!\w+ing), asserts that from the current position there are no word chars followed by ing and then match a , But \w does not match a comma so the asserting will always be true.

You can exclude matching a comma in the negative lookahead using a negated character class, and then also match until the first occurrence of a comma afterwards.

\bAfter\b(?![^,\n]*ing)[^,\n]*,

In parts, the pattern matches:

  • \bAfter\b Match the word After between word boundaries
  • (?![^,\n]*ing) Negative lookahead to assert that from the current position there is no occurrence of ing without crossing a comma
  • [^,\n]*, Match optional chars except a comma (or a newline if you don't want to cross lines)

Regex demo

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda